package com.swa99ylum.pxp.a.a007;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;

import org.apache.poi.ss.usermodel.CellType;
import org.apache.poi.xssf.usermodel.XSSFCell;
import org.apache.poi.xssf.usermodel.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;

/**
 * 测试：
 * isBlank() 方法
 */
public class Test2 {
	
	/**
	 * 测试：1、getLastRowNum() VS getLastCellNum()
	 */
	public static void main(String[] args) throws IOException {
		File file = new File("ccc.xlsx");
		System.out.println(file.getAbsolutePath());
		
		FileInputStream fis = new FileInputStream(file);
		XSSFWorkbook xwb = new XSSFWorkbook(fis);
		XSSFSheet sheet = xwb.getSheet("ddd");
		
		for (int i = 0; i <= sheet.getLastRowNum(); i++) {
			XSSFRow row = sheet.getRow(i);
			System.out.println(isBlank(row));
		}
	}
	
	
	@SuppressWarnings("deprecation")
	public static boolean isBlank(XSSFRow row) {
		if(row == null) {
			System.out.print("null 行 =>");
			return true;
		}else if(row.cellIterator().hasNext() == false) {
			System.out.print("0 cell 行 =>");
			return true;
		}else {
			//遍历 cell
			for (int i=row.getFirstCellNum(); i<row.getLastCellNum(); i++) {
				XSSFCell cell = row.getCell(i);
				
				//如果 "cell不为 null" 并且 "cell 不为 BLANK"，那么 当前 row 就不是 blank 的  
				if(cell!=null && cell.getCellType()!=CellType.BLANK.getCode())
					return false;
			}
			System.out.print("blank 行 =>");
			return true;
		} 
	}
	
	
}
